/*
 * @Author: 码农 2646995216@qq.com
 * @Date: 2025-02-19 16:28:03
 * @LastEditors: 码农 2646995216@qq.com
 * @LastEditTime: 2025-02-19 21:03:56
 * @FilePath: /pipe/PipeClientcpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "comm.hpp"


int main()
{
    //打开管道文件，如果没有就创建
    int wfd=open("./mypipe",O_WRONLY|O_CREAT);//返回该文件描述符的下标
    if(wfd<0)
    {
        //管道文件打开失败
        cout<<"open flase errno:"<<errno<<"errstring:"<<strerror(errno)<<endl;
        return 1;
    }

    string buffer;

    while(true)
    {
        cout<<"please write your message:"<<endl;
        getline(cin,buffer);//将从键盘输入的数据，存储到buffer中
        ssize_t n=write(wfd,buffer.c_str(),buffer.size());
        if(n<0)
        {
            cout<<"write flase"<<endl;
            break;
        }
    }
    
    close(wfd);//关闭管道
    return 0;
}